package edu.calvin.djs32.cs214.interpreters.calculator.primitives;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

import edu.calvin.cs214.hobbes2008.IntegerTIR;
import edu.calvin.cs214.hobbes2008.StringTIR;


public class AddPrimitiveTest {
	@Test
	public void shouldApplyInteger() {
	  assertEquals(new IntegerTIR(5), new AddPrimitive().apply(null, new IntegerTIR(2), new IntegerTIR(3)));
	  assertEquals(new IntegerTIR(6), new AddPrimitive().apply(null, new IntegerTIR(2), new IntegerTIR(4)));
	  assertEquals(new IntegerTIR(0), new AddPrimitive().apply(null, new IntegerTIR(-3), new IntegerTIR(3)));
	}
	
	@Test
	public void shouldApplyStrings(){
		assertEquals(new StringTIR("hi there"), new AddPrimitive().apply(null, new StringTIR("hi "), new StringTIR("there")));
		assertEquals(new StringTIR("foo bar"), new AddPrimitive().apply(null, new StringTIR("foo "), new StringTIR("bar")));	
		assertEquals(new StringTIR("derek slenk"), new AddPrimitive().apply(null, new StringTIR("derek "), new StringTIR("slenk")));
		assertEquals(new StringTIR(" slenk"), new AddPrimitive().apply(null, new StringTIR(" "), new StringTIR("slenk")));
	}
	
	@Test
	public void shouldApplyIntegerAndString(){
		assertEquals(new StringTIR("2 hi"), new AddPrimitive().apply(null, new IntegerTIR(2), new StringTIR(" hi")));
		assertEquals(new StringTIR("4 foo"), new AddPrimitive().apply(null, new IntegerTIR(4), new StringTIR(" foo")));
		assertEquals(new StringTIR("6 bar"), new AddPrimitive().apply(null, new IntegerTIR(6), new StringTIR(" bar")));
	}
	
	@Test
	public void shouldApplyStringAndInteger(){
		assertEquals(new StringTIR("hi 6"), new AddPrimitive().apply(null, new StringTIR("hi "), new IntegerTIR(6)));
		assertEquals(new StringTIR("foo -16"), new AddPrimitive().apply(null, new StringTIR("foo "), new IntegerTIR(-16)));
		assertEquals(new StringTIR("bar 31337"), new AddPrimitive().apply(null, new StringTIR("bar "), new IntegerTIR(31337)));
	}
	
	@Test
	public void shouldDoNestedStrings(){
		assertEquals(new StringTIR("hi there"), new AddPrimitive().apply(null, new StringTIR("hi"), new AddPrimitive().apply(null, new StringTIR(" "), new StringTIR("there"))));
	}
}
